package com.sbs.gaoxinqutoilet.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;

import com.sbs.gaoxinqutoilet.R;
import com.sbs.gaoxinqutoilet.utils.LogUtils;
import com.sbs.gaoxinqutoilet.utils.SystemBarTintManager;

/**
 * Created by 聪明一只哈 on 2018/7/9.
 * Time: 2018/7/9  14:37
 */

public class SplaActivity extends Activity {

    private ImageView iv;
    private ImageView img_guang;
    private RelativeLayout relativeLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash_two);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            // 创建状态栏的管理实例
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            // 激活状态栏设置
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintColor(getResources().getColor(R.color.status_translate));

        }
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                                 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                               | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.TRANSPARENT);
        }

        //initImage();

        initView();
        initData();
    }

    private void initImage(){

        android.util.DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
        int width = displayMetrics.widthPixels;  // 屏幕宽度（像素）
        int heigh = displayMetrics.heightPixels;  // 屏幕高度（像素）
        LogUtils.i("onCreatewidth: ", "heigh" + heigh + "width" + width);
        img_guang = (ImageView) this.findViewById(R.id.img_guang);

        float jishu = width / 375f;

        RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) img_guang.getLayoutParams();
        // 取控件背景当前的布局参数
        linearParams.width = (int) (jishu * 375);
        linearParams.height = (int) (jishu * 540);
        //        linearParams.bottomMargin=(int) (jishu * 13);
        img_guang.setLayoutParams(linearParams); // 使设置好的布局参数应用到控件

    }

    private void initView() {
        //iv = (ImageView) this.findViewById(R.id.logo);

        relativeLayout = (RelativeLayout) this.findViewById(R.id.logo_bg);
        //iv.setImageResource(R.drawable.splashb);

        AlphaAnimation alphaAnimation = new AlphaAnimation(0.2f, 1.0f);
        alphaAnimation.setDuration(2000);

        //iv.startAnimation(alphaAnimation);
        relativeLayout.startAnimation(alphaAnimation);

        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                Log.i("donghua", "onAnimationStart: start");
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Intent intent = new Intent();
                intent.setClass(SplaActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });


    }

    private void initData() {



    }
}
